<template>
  <el-dialog
    :title="title"
    v-model="dialogVisible"
    @close="dialogFormVisible"
    width="500px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-form ref="formRef" :model="form" label-width="100px">
      <el-form-item label="用户id">
        <el-input :value="info?.submitter" disabled></el-input>
      </el-form-item>
      <el-form-item label="奖励积分" prop="points">
        <el-input-number v-model="form.points" :min="1"></el-input-number>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="form.remark"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="cancelFunc">取消</el-button>
      <el-button type="primary" @click="onSubmit" :loading="loading">确认</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { rewardApi, updateApi } from "@/api/temple";
import { ElMessage } from "element-plus";
import { inject, ref, watch } from "vue";
const title = ref("积分奖励");
const dialogVisible = ref(false);
const info = ref<any>();
const form = ref({
  user_id: 0,
  points: 0,
  remark: "古庙保护计划奖励",
});
const formRef = ref<any>(null);
const loading = ref(false);
const dialogFormVisible = () => {
  loading.value = false;
  dialogVisible.value = false;
};
const open_type = ref("");
const open = (row?: any) => {
  info.value = row;
  form.value.user_id = row.submitter;
  form.value.points = 1;
  form.value.remark = "古庙保护计划奖励";
  dialogVisible.value = true;
};
const onSubmit = () => {
  formRef.value.validate((valid: any) => {
    if (valid) {
      loading.value = true;
      rewardApi(form.value).then((res) => {
        loading.value = false;
        ElMessage.success("奖励成功");
        dialogFormVisible();
      });
    } else {
      return false;
    }
  });
};
/*取消*/
const cancelFunc = () => {
  loading.value = false;
  dialogFormVisible();
};
defineExpose({ open });
</script>

<style lang="scss" scoped>
.tip {
  font-size: 14px;
  padding: 10px 0;
}
</style>
